Skip to content

[Prim] add reduce_as op for paddle - #63064

Merged
cyber-pioneer merged 42 commits into
PaddlePaddle:developfrom
zeroRains:sum
Apr 19, 2024
Merged

cyber-pioneer merged 42 commits into
PaddlePaddle:developfrom
zeroRains:sum

Conversation

@zeroRains

@zeroRains zeroRains commented Mar 27, 2024 •

Copy link
Copy Markdown
Contributor

PR Category

Others

PR Types

New features

Description

由于broadcast类算子的反向拆解无法适配动态shape,

在静态shape中的例子如下,

x.shape = [2,3]
y.shape = [1,3]
z = x+y 
# z.shape = [2,3]
# dz -> dy
reduce_dim = get_reduce_dim(y.shape, z.shape)
# reduce_dim = [0]
dy = sum(dz, reduce_dim, True)

但在动态shape的编译期拿不到reduce_dim,于是要添加reduce_as算子,其伪代码如下:

def reduce_as(x: Tensor, y: Tensor):
      reduce_dim = get_reduce_dim(x.shape, y.shape)
      res = sum(x, reduce_dim)
      return res

有了这个算子之后,动态shape的场景写法如下:

x.shape = [-1,3]
y.shape = [1,3]
z = x+y 
# z.shape = [-1,3]
# dz -> dy
# dz.shape = [-1,3]
dy = reduce_as(dz, y)

这个pr就是实现对reduce_as op的添加

@paddle-bot

paddle-bot Bot commented Mar 27, 2024

Copy link
Copy Markdown

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册。
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot Bot added the contributor External developers label Mar 27, 2024
@paddle-bot

paddle-bot Bot commented Mar 27, 2024

Copy link
Copy Markdown

❌ The PR is not created using PR's template. You can refer to this Demo.
Please use PR's template, it helps save our maintainers' time so that more developers get helped.

Comment thread paddle/phi/api/yaml/backward.yaml Resolved
Comment thread test/legacy_test/test_sum_as_op.py Resolved
Comment thread test/legacy_test/test_sum_as_op.py Resolved
Comment thread test/legacy_test/test_sum_as_op.py Outdated
self.python_api = paddle.sum_as
self.public_python_api = paddle.sum_as
self.op_type = "sum_as"
self.prim_op_type = "prim"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个算子目前没有反向拆解,这里是不能设置的

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@cyber-pioneer

Copy link
Copy Markdown
Collaborator

补充动态shape的单侧

@zeroRains zeroRains closed this Apr 4, 2024
@zeroRains zeroRains reopened this Apr 4, 2024
@zeroRains zeroRains changed the title [Prim] add sum_as op for paddle [Prim] add reduce_as op for paddle Apr 9, 2024
@zeroRains

Copy link
Copy Markdown
Contributor Author

由于在本地cuda 11.2环境, 本地cuda12.0环境 以及CI环境都无法复现test_assign_pos_op 单测出错的场景,现将该PR的实现部分进行拆解,分成多个子PR,确认是哪个部分的改动引起了这个单测出错。这些PR并不需要Review和Merge具体PR如下:

reduce_as 前向计算: #63652

@Xreki Xreki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for op-benchmark ci

@sunzhongkai588 sunzhongkai588 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM,中文也同步增加文档吧

@XieYunshen XieYunshen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

'float64',
'int16',
'int32',
'int64',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we support other data type of complex64/128、uint8 andint8?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

后续的PR再进行补充吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor External developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants